﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class my_givelist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TUser1.CheckUser(this);

            //设定状态
            if ((this.Session["ecrm_email"] == null) || (this.Session["ecrm_email"].ToString() == ""))
            {
                userstatus1.Text = "你好，请 <a href=\"main.aspx\">登录</a>或 ";
                userstatus2.Text = "<a href=\"./user/user_reg.aspx\">注册</a>";
            }
            else
            {
                string sid = this.Session["ecrm_uid"].ToString();
                TUser oUser = new TUser(sid);
                oUser.Select();
                string bigname = oUser.BigName;

                userstatus1.Text = "<a onclick='javascript:location.href=\"./user/user_myself.aspx\"' onmouseover='this.style.cursor=\"pointer\"' onmouseout='this.style.backgroundColor=\"\"'>" + bigname + "的设置</a>";
                userstatus2.Text = "<a onclick='javascript:location.href=\"./user/user_logout.aspx\"' onmouseover='this.style.cursor=\"pointer\"' onmouseout='this.style.backgroundColor=\"\"'>退出</a>";
            }

            myuid.Text = this.Session["ecrm_uid"].ToString();

            linkmanlist.InnerHtml = manlist(myuid.Text);
        }
        else
        {
        }
    }

    private string manlist(string inman)
    {
        string result = "<table id=\"manlist\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">";

        result += "<thead>";
        result += "<tr height=\"30\">";
        result += "<td width=\"30\" align=\"center\">序号</td>";
        result += "<td width=\"80\">姓名</td>";
        result += "<td width=\"40\" align=\"center\">性别</td>";
        result += "<td width=\"60\">手机</td>";
        result += "<td>公司</td>";
        result += "<td width=\"40\" align=\"center\">赠刊</td>";
        result += "<td width=\"100\" align=\"center\">理由</td>";
        result += "<td width=\"60\" align=\"center\">开始时间</td>";
        result += "<td width=\"60\" align=\"center\">终止时间</td>";
        result += "<td width=\"120\" colspan=3 align=\"center\">操作</td>";
        result += "</tr>";
        result += "</thead>";
        result += "<tbody>";
        int iNum = 1;
        string sSql = "select uid,linkman,sex,mobile,company,status,giveexpl,givebdate,giveedate from vw_givelist where inman='"+inman+"' order by status desc,company,linkman";
        TSqlDBReader oList = new TSqlDBReader(sSql);
        while (oList.FDataReader.Read())
        {
            string uid = oList.FDataReader.GetValue(0).ToString();
            result += "<tr id=\"" + uid + "\" height=\"26\">";
            result += "<td width=\"30\" align=\"center\">" + iNum.ToString() + "</td>";
            result += "<td width=\"80\">" + oList.FDataReader.GetValue(1).ToString() + "</td>";
            result += "<td width=\"40\" align=\"center\">" + oList.FDataReader.GetValue(2).ToString() + "</td>";
            result += "<td width=\"60\">" + oList.FDataReader.GetValue(3).ToString() + "</td>";
            result += "<td>" + oList.FDataReader.GetValue(4).ToString() + "</td>";
            
            int iFlag = Convert.ToInt32(oList.FDataReader.GetValue(5).ToString());
            switch (iFlag)
            {
                case 0://未申请
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"#cccccc\">未申请</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\"></td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">-</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">-</td>";
                    break;
                case 1://新申请
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"#669999\">新申请</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\">" + oList.FDataReader.GetValue(6).ToString() + "</td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(7))).ToString("yy-MM-dd") + "</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(8))).ToString("yy-MM-dd") + "</td>";
                    break;
                case 2://续申请
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"#cccc99\">续申请</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\">" + oList.FDataReader.GetValue(6).ToString() + "</td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(7))).ToString("yy-MM-dd") + "</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(8))).ToString("yy-MM-dd") + "</td>";
                    break;
                case 3://已取消
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"#cccccc\">已取消</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\">" + oList.FDataReader.GetValue(6).ToString() + "</td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(7))).ToString("yy-MM-dd") + "</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(8))).ToString("yy-MM-dd") + "</td>";
                    break;
                case 4://已通过
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"green\">已通过</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\">" + oList.FDataReader.GetValue(6).ToString() + "</td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(7))).ToString("yy-MM-dd") + "</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(8))).ToString("yy-MM-dd") + "</td>";
                    break;
                case 5://未通过
                    result += "<td id=\"" + uid + "_1\" width=\"50\" align=\"center\"><font color=\"red\">未通过</font></td>";
                    result += "<td id=\"" + uid + "_2\" width=\"100\">" + oList.FDataReader.GetValue(6).ToString() + "</td>";
                    result += "<td id=\"" + uid + "_3\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(7))).ToString("yy-MM-dd") + "</td>";
                    result += "<td id=\"" + uid + "_4\" width=\"60\" align=\"center\">" + ((DateTime)(oList.FDataReader.GetValue(8))).ToString("yy-MM-dd") + "</td>";
                    break;
            }
            
            result += "<td id=\"" + uid + "_apply\" width=\"46\" align=\"center\" class=\"td_apply\" onclick=\"zmag_show('"+uid+"','1')\"><span>新申请</span></td>";
            result += "<td id=\"" + uid + "_update\" width=\"46\" align=\"center\" class=\"td_update\" onclick=\"zmag_show('" + uid + "','2')\"><span>续申请</span></td>";
            result += "<td id=\"" + uid + "_cancel\" width=\"46\" align=\"center\" class=\"td_cancel\" onclick=\"zmag_show('" + uid + "','3')\"><span>取消<span></td>";
            result += "</tr>";
            iNum++;
        }
        oList.Free();
        result += "</tbody>";
        result += "</table>";

        return result;
    }
}
